package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Json字符串请求参数的接收
 * 注意：形参前需要增加@RequestBody注解
 * @author stone
 * @date 2022/12/23 17:06
 */
@RestController
@RequestMapping("user")
public class UserController {
    /**
     * String
     * {"username":"songge","password":"niupi","birthday":"2022-07-12"}
     * @return
     */
    @RequestMapping("login")
    public BaseRespVo login(@RequestBody String result) {
        System.out.println(result);
        return BaseRespVo.ok();
    }

    /**
     * 引用类型对象
     * {"username":"songge","password":"niupi","age":50,"birthday":"1995-03-19"}
     * @return
     */
    @RequestMapping("login2")
    public BaseRespVo login2(@RequestBody User user) {
        System.out.println(user);
        return BaseRespVo.ok();
    }

    /**
     * Map → LinkedHashMap
     * {"username":"songge","password":"niupi","age":50,"birthday":"1995-03-19"}
     * @return
     */
    @RequestMapping("login3")
    public BaseRespVo login3(@RequestBody Map map) {
        System.out.println(map);
        return BaseRespVo.ok();
    }
}
